package com.nantian.logic.controller.mainControl.campusControl;

import com.cuit.springboot.gdao.campus.CampusRelateMapper;
import com.nantian.logic.entity.mainEntity.campusEntity.CampusEntity;
import com.nantian.logic.repository.mainRepo.camRepo.CampusRepository;
import com.nantian.logic.utils.UniversalResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping(value="/campus")
public class CampusController {

    @Autowired CampusRepository camRepo;
    @Autowired CampusRelateMapper camMapper;

    @PostMapping(value="/camlist")
    public UniversalResult<List<CampusEntity>> FindAllCompusInThisSchool(){
        List<CampusEntity> list=camRepo.findAll();
        return new UniversalResult(UniversalResult.SUCCESS,"successful",list);
    }

    @PostMapping(value="/camsave")
    public UniversalResult insertCam(@RequestBody CampusEntity camEnt){
        camRepo.save(camEnt);
        return new UniversalResult(UniversalResult.SUCCESS,"successful");
    }

    @PostMapping(value="/areacampus")
    public UniversalResult<List<CampusEntity>> FindCampusByUniversity(@RequestBody CampusEntity camEnt){
        List<CampusEntity> list=camRepo.findAllByAreaid(camEnt.getAreaid());
        return new UniversalResult<List<CampusEntity>>(UniversalResult.SUCCESS,"ok",list);
    }

    @PostMapping(value="/addcampus")
    public UniversalResult<List<CampusEntity>> AddNewCampus(@RequestBody CampusEntity camEnt){
        camRepo.save(camEnt);
        //增加新的社团后,返回客户端新的社团信息
        List<CampusEntity> list=camRepo.findAllByAreaid(camEnt.getAreaid());
        return new UniversalResult<List<CampusEntity>>(UniversalResult.SUCCESS,"ok",list);
    }

    @PostMapping(value="/typeAndlevel")
    public UniversalResult<List> TypeAndLevel(){
        List list=new ArrayList();
        list.add(camMapper.selectAllLevel());
        list.add(camMapper.selectAllType());
        return new UniversalResult<List>(UniversalResult.SUCCESS,"ok",list);
    }
}
